package com.foo.Writer;

import javax.ejb.Stateless;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Session Bean implementation class Writer
 */
@Stateless
public class Writer implements WriterRemote, WriterLocal 
{

    public Writer() 
    {
		System.out.println("In Writer class");
    }
    
    @Override
    public void selectwriter(String filename, String[] data, String type)
    {
    	ApplicationContext context = new ClassPathXmlApplicationContext("/beans.xml");

    	if(filename.contains(".xml"))
    	{
    	//ApplicationContext context = new ClassPathXmlApplicationContext("/beans.xml");
		WriterInterface forumWriter = (WriterInterface) context.getBean("XMLWriter");  
		System.out.println("In Writer xml");
		forumWriter.generateFile(filename, data, type);	
    	}
    	if(filename.contains(".txt") || filename.contains(".csv"))
    	{
		WriterInterface forumWriter = (WriterInterface) context.getBean("TXTCSVWriter");
		System.out.println("In Writer tst csv");
		forumWriter.generateFile(filename, data, type);	
    	}
    	if(filename.contains(".json"))
    	{
		WriterInterface forumWriter = (WriterInterface) context.getBean("JSONWriter");  
		System.out.println("In Writer json");
		forumWriter.generateFile(filename, data, type);	
    	}    	
	
    }

}
